package com.ruoyi.web.cp.service.rm;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.google.common.collect.Lists;
import com.ruoyi.web.core.config.ConfigLoader;
import com.ruoyi.web.cp.domain.rm.RmGame;
import com.ruoyi.web.cp.domain.rm.RmResult;
import com.ruoyi.web.cp.service.WinxinService;
import com.ruoyi.web.mapper.RmGameMapper;
import com.ruoyi.web.mapper.RmResultMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.nio.file.FileSystems;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class RmobGroup3Service {
    @Autowired
    private RmGameMapper rmGameMapper;
    @Autowired
    private WinxinService winxinService;
    @Autowired
    private RmResultMapper rmResultMapper;
    @Autowired
    private ConfigLoader configLoader;

    public void execute(int days, String key) {
        List<RmGame> rmGames = rmGameMapper.selectLastNDays(days);
        List<String> gameIds = rmGames.stream().map(RmGame::getGameId).collect(Collectors.toList());

        List<RmResult> rmResults = rmResultMapper.selectByGameIds(gameIds);
        Map<String, RmResult> gameIdToRmResultMap = rmResults.stream().collect(Collectors.toMap(
                RmResult::getGameId,
                v -> v,
                (existing, replacement) -> existing
        ));

        List<RmGame> list1 = new ArrayList<>();
        List<RmGame> list2 = new ArrayList<>();
        List<RmGame> list3 = new ArrayList<>();
        List<RmGame> list4 = new ArrayList<>();
        List<RmGame> list5 = new ArrayList<>();
        List<RmGame> list6 = new ArrayList<>();
        List<RmGame> list7 = new ArrayList<>();
        List<RmGame> list8 = new ArrayList<>();
        List<RmGame> list9 = new ArrayList<>();
        List<RmGame> list10 = new ArrayList<>();
        List<RmGame> list11 = new ArrayList<>();
        List<RmGame> list12 = new ArrayList<>();
        List<RmGame> list13 = new ArrayList<>();
        List<RmGame> list14 = new ArrayList<>();
        List<RmGame> list15 = new ArrayList<>();

        for (RmGame rmGame : rmGames) {
            RmGame.ObDetail obDetail = rmGame.obPlvFromJson();
            if (obDetail == null) {
                continue;
            }
            String goal_half_desc = obDetail.getGoal_half_desc();//半场大小球
            String goal_desc = obDetail.getGoal_desc();//大小球
            String asian_desc = obDetail.getAsian_desc();//亚盘让球
            String asian_half_desc = obDetail.getAsian_half_desc();//亚盘半场让球

            //1.半场大小球=1.5 && 亚盘半场让球=+0.5
            if (StrUtil.isAllNotBlank(goal_half_desc, asian_half_desc)
                    && "1.5".equals(goal_half_desc)
                    && "+0.5".equals(asian_half_desc)
            ) {
                list1.add(rmGame);
            }

            //2.半场大小球=1.5 && 亚盘半场让球=-0.5/1
            if (StrUtil.isAllNotBlank(goal_half_desc, asian_half_desc)
                    && "1.5".equals(goal_half_desc)
                    && "-0.5/1".equals(asian_half_desc)
            ) {
                list2.add(rmGame);
            }

            //3.半场大小球=1.5 && 亚盘全场让球=-1/1.5
            if (StrUtil.isAllNotBlank(goal_half_desc, asian_desc)
                    && "1.5".equals(goal_half_desc)
                    && "-1/1.5".equals(asian_desc)
            ) {
                list3.add(rmGame);
            }

            //4.半场大小球=1.5 && 亚盘全场让球=-1.5
            if (StrUtil.isAllNotBlank(goal_half_desc, asian_desc)
                    && "1.5".equals(goal_half_desc)
                    && "-1.5".equals(asian_desc)
            ) {
                list4.add(rmGame);
            }

            //5.全场大小球=3/3.5 && 亚盘全场让球=-1
            if (StrUtil.isAllNotBlank(goal_desc, asian_desc)
                    && "3/3.5".equals(goal_desc)
                    && "-1".equals(asian_desc)
            ) {
                list5.add(rmGame);
            }

            //6.全场大小球=3/3.5 && 亚盘全场让球=-0/0.5
            if (StrUtil.isAllNotBlank(goal_desc, asian_desc)
                    && "3/3.5".equals(goal_desc)
                    && "-0/0.5".equals(asian_desc)
            ) {
                list6.add(rmGame);
            }

            //7.半场大小球=1.5 && 亚盘半场让球=-0.5 && 亚盘全场让球=-1/1.5
            if (StrUtil.isAllNotBlank(goal_half_desc, asian_half_desc, asian_desc)
                    && "1.5".equals(goal_half_desc)
                    && "-0.5".equals(asian_half_desc)
                    && "-1/1.5".equals(asian_desc)
            ) {
                list7.add(rmGame);
            }

            //8.半场大小球=1/1.5 && 全场大小球=3/3.5 && 亚盘全场让球=-0/0.5
            if (StrUtil.isAllNotBlank(goal_half_desc, goal_desc, asian_desc)
                    && "1/1.5".equals(goal_half_desc)
                    && "3/3.5".equals(goal_desc)
                    && "-0/0.5".equals(asian_desc)
            ) {
                list8.add(rmGame);
            }

            //9.全场大小球=3/3.5 && 亚盘半场让球=-0.5 && 亚盘全场让球=-1
            if (StrUtil.isAllNotBlank(goal_desc, asian_half_desc, asian_desc)
                    && "3/3.5".equals(goal_desc)
                    && "-0.5".equals(asian_half_desc)
                    && "-1".equals(asian_desc)
            ) {
                list9.add(rmGame);
            }

            //10.半场大小球=1/1.5 && 全场大小球=3/3.5 && 亚盘全场让球=-1
            if (StrUtil.isAllNotBlank(goal_half_desc, goal_desc, asian_desc)
                    && "1/1.5".equals(goal_half_desc)
                    && "3/3.5".equals(goal_desc)
                    && "-1".equals(asian_desc)
            ) {
                list10.add(rmGame);
            }

            //11.半场大小球=1.5 && 亚盘半场让球=-0.5
            if (StrUtil.isAllNotBlank(goal_half_desc, asian_half_desc)
                    && "1.5".equals(goal_half_desc)
                    && "-0.5".equals(asian_half_desc)
            ) {
                list11.add(rmGame);
            }

            //12.全场大小球=3.5 && 亚盘半场让球=-0/0.5
            if (StrUtil.isAllNotBlank(goal_desc, asian_half_desc)
                    && "3.5".equals(goal_desc)
                    && "-0/0.5".equals(asian_half_desc)
            ) {
                list12.add(rmGame);
            }

            //13.半场大小球=1.5 && 全场大小球=3/3.5
            if (StrUtil.isAllNotBlank(goal_half_desc, goal_desc)
                    && "1.5".equals(goal_half_desc)
                    && "3/3.5".equals(goal_desc)
            ) {
                list13.add(rmGame);
            }

            //14.半场大小球=1.5 && 全场大小球=3.5 && 亚盘半场让球=-0/0.5
            if (StrUtil.isAllNotBlank(goal_half_desc, goal_desc, asian_half_desc)
                    && "1.5".equals(goal_half_desc)
                    && "3.5".equals(goal_desc)
                    && "-0/0.5".equals(asian_half_desc)
            ) {
                list14.add(rmGame);
            }

            //15.全场大小球=3.5 && 亚盘半场让球=-0.5
            if (StrUtil.isAllNotBlank(goal_desc, asian_half_desc)
                    && "3.5".equals(goal_desc)
                    && "-0.5".equals(asian_half_desc)
            ) {
                list15.add(rmGame);
            }
        }

        String path = configLoader.getRmPath() + "rmob-group3" + FileSystems.getDefault().getSeparator() + "方案汇总-" + days + "天.xlsx";
        File tempFile = new File(path);
        // 如果文件已存在，先删除
        if (tempFile.exists()) {
            FileUtil.del(tempFile);
        }
        // 创建 ExcelWriter 对象
        ExcelWriter writer = ExcelUtil.getWriter(tempFile);

        sendList1("方案1-半场大小球1.5 & 亚盘半场让球+0.5", list1, gameIdToRmResultMap, writer);
        sendList2("方案2-半场大小球1.5 & 亚盘半场让球-0.75", list2, gameIdToRmResultMap, writer);
        sendList3("方案3-半场大小球1.5 & 亚盘全场让球-1.25", list3, gameIdToRmResultMap, writer);
        sendList4("方案4-半场大小球1.5 & 亚盘全场让球-1.5", list4, gameIdToRmResultMap, writer);
        sendList5("方案5-全场大小球3.25 & 亚盘全场让球-1", list5, gameIdToRmResultMap, writer);
        sendList6("方案6-全场大小球3.25 & 亚盘全场让球-0.25", list6, gameIdToRmResultMap, writer);
        sendList7("方案7-半场大小球1.5 & 亚盘半场让球-0.5 & 亚盘全场让球-1.25", list7, gameIdToRmResultMap, writer);
        sendList8("方案8-半场大小球1.25 & 全场大小球3.25 亚盘全场让球-0.25", list8, gameIdToRmResultMap, writer);
        sendList9("方案9-全场大小球3.25 & 亚盘半场让球-0.5 & 亚盘全场让球-1", list9, gameIdToRmResultMap, writer);
        sendList10("方案10-半场大小球1.25 & 全场大小球3.25 & 亚盘全场让球-1", list10, gameIdToRmResultMap, writer);
        sendList11("方案11-半场大小球1.5 & 亚盘半场让球-0.5", list11, gameIdToRmResultMap, writer);
        sendList12("方案12-全场大小球3.5 & 亚盘半场让球-0.25", list12, gameIdToRmResultMap, writer);
        sendList13("方案13-半场大小球1.5 & 全场大小球3.25", list13, gameIdToRmResultMap, writer);
        sendList14("方案14-半场大小球1.5 & 全场大小球3.5 & 亚盘半场让球-0.25", list14, gameIdToRmResultMap, writer);
        sendList15("方案15-全场大小球3.5 && 亚盘半场让球-0.5", list15, gameIdToRmResultMap, writer);

        // 关闭流
        writer.close();

        winxinService.sendQlMedia(key, path);
    }

    private String get00MinOdds(RmGame rmGame) {
        List<RmGame.Detail> allPlv = rmGame.allPlvFromJson();
        String rm00 = "";
        if (CollUtil.isNotEmpty(allPlv)) {
            Map<String, String> allPlvDict = allPlv.stream().collect(Collectors.toMap(
                    RmGame.Detail::getScore,
                    RmGame.Detail::getPlv,
                    (existing, replacement) -> existing
            ));
            rm00 = allPlvDict.get("0-0");
        }
        return rm00;
    }

    private String get81To85MinOdds(RmGame rmGame) {
        List<RmGame.Detail> goalTime5Plvs = rmGame.goalTime5PlvFromJson();
        String rm00 = "";
        if (CollUtil.isNotEmpty(goalTime5Plvs)) {
            Map<String, String> allPlvDict = goalTime5Plvs.stream().collect(Collectors.toMap(
                    RmGame.Detail::getScore,
                    RmGame.Detail::getPlv,
                    (existing, replacement) -> existing
            ));
            rm00 = allPlvDict.get("81:00-85:59");
        }
        return rm00;
    }

    public void sendList1(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap,
                          ExcelWriter writer) {
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "亚盘半场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getAsian_half_desc());
            } else {
                for (int i = 0; i < 2; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 亚盘半场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList2(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "亚盘半场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getAsian_half_desc());
            } else {
                for (int i = 0; i < 1; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 亚盘半场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList3(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "亚盘全场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_desc());
            } else {
                for (int i = 0; i < 2; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 亚盘全场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList4(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "亚盘半场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getAsian_desc());
            } else {
                for (int i = 0; i < 2; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 亚盘全场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList5(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "全场大小球", "亚盘全场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_desc());
            } else {
                for (int i = 0; i < 2; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 全场大小球
                12 * 256, // 亚盘全场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList6(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "全场大小球", "亚盘全场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_desc());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 全场大小球
                12 * 256, // 亚盘全场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList7(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "亚盘半场让球", "亚盘全场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getAsian_half_desc());
                row.add(obPlvs.getAsian_desc());
            } else {
                for (int i = 0; i < 4; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 亚盘半场让球
                12 * 256, // 亚盘全场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList8(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "全场大小球", "亚盘全场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_desc());
            } else {
                for (int i = 0; i < 1; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 全场大小球
                12 * 256, // 亚盘全场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList9(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "全场大小球", "亚盘半场让球", "亚盘全场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_half_desc());
                row.add(obPlvs.getAsian_desc());
            } else {
                for (int i = 0; i < 2; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 全场大小球
                12 * 256, // 亚盘半场让球
                12 * 256, // 亚盘全场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList10(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "全场大小球", "亚盘全场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_desc());
            } else {
                for (int i = 0; i < 2; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 全场大小球
                12 * 256, // 亚盘全场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList11(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "亚盘半场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getAsian_half_desc());
            } else {
                for (int i = 0; i < 2; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 全场大小球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList12(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "全场大小球", "亚盘半场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_half_desc());
            } else {
                for (int i = 0; i < 4; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 全场大小球
                12 * 256, // 亚盘半场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList13(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "全场大小球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getGoal_desc());
            } else {
                for (int i = 0; i < 4; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 全场大小球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList14(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "半场大小球", "全场大小球", "亚盘半场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_half_desc());
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_half_desc());
            } else {
                for (int i = 0; i < 2; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 半场大小球
                12 * 256, // 全场大小球
                12 * 256, // 亚盘半场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }

    public void sendList15(String name, List<RmGame> list1, Map<String, RmResult> gameIdToRmResultMap, ExcelWriter writer) {
        writer.writeRow(name, false);
        // 手动设置表头
        String[] headers = {"日期", "联赛", "主队", "客队", "RM00", "81-85",
                "全场大小球", "亚盘半场让球",
                "半场结果", "全场结果", "首进球时间"
        };
        writer.passRows(1);
        writer.merge(headers.length - 1, name);
        writer.writeHeadRow(Arrays.asList(headers));

        // 写入数据（假设 RmobDoubleMerge 有对应的 getter 方法）
        for (RmGame rmGame : list1) {
            List<String> row = Lists.newArrayList();
            row.add(rmGame.parseDateStr());       // 日期
            row.add(rmGame.getLeague());          // 联赛
            row.add(rmGame.getTeamA());           // 主队
            row.add(rmGame.getTeamB());          // 客队
            row.add(get00MinOdds(rmGame));      //RM00
            row.add(get81To85MinOdds(rmGame));   //81-86

            RmGame.ObDetail obPlvs = rmGame.obPlvFromJson();
            if (obPlvs != null) {
                row.add(obPlvs.getGoal_desc());
                row.add(obPlvs.getAsian_half_desc());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            RmResult rmResult = gameIdToRmResultMap.get(rmGame.getGameId());
            if (rmResult != null) {
                row.add(rmResult.getHalfScore());
                row.add(rmResult.getAllScore());
                row.add(rmResult.getGoalTime());
            } else {
                for (int i = 0; i < 3; i++) {
                    row.add("");
                }
            }

            writer.writeRow(row);
        }
        int[] columnWidths = {
                18 * 256, // 日期
                15 * 256, // 联赛
                20 * 256, // 主队
                20 * 256, // 客队
                12 * 256, // RM00
                12 * 256, // 81-86
                12 * 256, // 全场大小球
                12 * 256, // 亚盘半场让球
                12 * 256, // 半场结果
                12 * 256, // 全场结果
                12 * 256  // 首进球时间
        };

        for (int i = 0; i < columnWidths.length; i++) {
            writer.getSheet().setColumnWidth(i, columnWidths[i]);
        }
    }
}
